document.addEventListener('DOMContentLoaded', function () {
    const navLinks = document.querySelectorAll('.category-nav a');

    navLinks.forEach(link => {
        link.addEventListener('click', function (e) {
            e.preventDefault();
            const targetId = this.getAttribute('href').substring(1);
            history.pushState({}, '', `#${targetId}`);
            switchContent(targetId);
        });
    });

    window.addEventListener('popstate', () => {
        const hash = window.location.hash.substring(1) || 'history';
        switchContent(hash);
    });

    const initialHash = window.location.hash.substring(1);
    switchContent(initialHash || 'history');
});

function switchContent(targetId) {
    document.querySelectorAll('.category-nav a').forEach(link => link.classList.remove('active'));
    document.querySelectorAll('.content-section').forEach(section => section.classList.remove('active'));

    const targetSection = document.getElementById(targetId);
    const targetLink = document.querySelector(`a[href="#${targetId}"]`);

    if (targetSection && targetLink) {
        targetLink.classList.add('active');
        targetSection.classList.add('active');
    }
}


// Image fly-in effect
       document.addEventListener('DOMContentLoaded', function () {
  const navLinks = document.querySelectorAll('.category-nav a');

  navLinks.forEach(link => {
    link.addEventListener('click', function (e) {
      e.preventDefault();
      const targetId = this.getAttribute('href').substring(1);
      history.pushState({}, '', `#${targetId}`);
      switchContent(targetId);
    });
  });

  window.addEventListener('popstate', () => {
    const hash = window.location.hash.substring(1) || 'history';
    switchContent(hash);
  });

  const initialHash = window.location.hash.substring(1);
  switchContent(initialHash || 'history');
});

function switchContent(targetId) {
  document.querySelectorAll('.category-nav a').forEach(link => link.classList.remove('active'));
  document.querySelectorAll('.content-section').forEach(section => section.classList.remove('active'));

  const targetSection = document.getElementById(targetId);
  const targetLink = document.querySelector(`a[href="#${targetId}"]`);

  if (targetSection && targetLink) {
    targetLink.classList.add('active');
    targetSection.classList.add('active');

    // Trigger fly-in animation for images in the active content section
    targetSection.querySelectorAll('.fly-in').forEach(item => {
      item.classList.remove('active'); // Remove active class to retrigger animation
      void item.offsetWidth; // Trigger repaint
      item.classList.add('active'); // Add active class to trigger animation
    });
  }
}
       


document.getElementById('print-pdf-btn').addEventListener('click', function() {
    // Use window.print() method to open browser print preview
    window.print();
});